<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "shbb_park".
 *
 * @property integer $id
 * @property string $code
 * @property string $name
 * @property string $addr
 * @property string $scale
 * @property integer $build_date
 * @property integer $start_date
 * @property string $introduction
 * @property string $tel
 * @property string $email
 * @property string $comment
 * @property string $map_image
 * @property string $qualification_image
 * @property integer $pricipal_id
 * @property integer $company_id
 * @property integer $contact_id
 *
 * @property Crop[] $Crops
 * @property Equip[] $Equips
 * @property Land[] $Lands
 * @property Person $contact
 * @property Company $company
 * @property Person $pricipal
 */
class Park extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'shbb_park';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'build_date', 'start_date', 'pricipal_id', 'company_id', 'contact_id'], 'integer'],
            [['introduction'], 'string'],
            [['code', 'name', 'addr', 'scale', 'tel', 'email', 'comment', 'map_image', 'qualification_image'], 'string', 'max' => 255],
            [['code'], 'unique'],
            ['email', 'email'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '园区ID',
            'code' => '园区编号',
            'name' => '园区名称',
            'addr' => '园区地址',
            'scale' => '园区规模',
            'build_date' => '创园时间',
            'start_date' => '初产时间',
            'introduction' => '简介',
            'tel' => '联系电话',
            'email' => '电子邮箱',
            'comment' => '备注',
            'map_image' => '地图',
            'qualification_image' => '资质照片',
            'pricipal_id' => '负责人',
            'company_id' => ' 所属公司',
            'contact_id' => ' 联系人',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCrops()
    {
        return $this->hasMany(Crop::className(), ['park_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquips()
    {
        return $this->hasMany(Equip::className(), ['park_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLands()
    {
        return $this->hasMany(Land::className(), ['park_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getContact()
    {
        return $this->hasOne(Person::className(), ['id' => 'contact_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCompany()
    {
        return $this->hasOne(Company::className(), ['id' => 'company_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPricipal()
    {
        return $this->hasOne(Person::className(), ['id' => 'pricipal_id']);
    }
}
